// pages/share/share.js
var app = getApp()
let drawQrcode = require("../../utils/weapp-qrcode.js")    
// let url = encodeURIComponent('../../pages/blogin/login?news_id=' + this.data.news_id);
// let url = 'https://open.weixin.qq.com/sns/getexpappinfo?appid=wxe329ad2878856a4c&path=pages%2Faacplace%2Faacplace.html%3Fid%3D192&state%3D1#wechat-redirect';
 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tphei:app.globalData.winwidth*0.86/4*1.3,
    modalHidden:true,
    time: '12:01',
    date: '',site:'',
    time2: '12:02',
    chuantu:'https://www.juquduo.com/static/resourse/zhuce/上传.jpg',
    text:'',
    img1:'',site:'',
    acid:''
  },
  onShareAppMessage: function(res) {
    // console.log(res);
    var url = "../dgame1/dgame1"
    if (res.from === 'button') {
      // 来自页面内转发按钮
      return{
        title:"进入活动",
        path:"/pages/dgame1/dgame1",
      }
      // console.log(res.target)
    }
    return {
      title: '自定义转发标题',
      path:"/pages/dgame1/dgame1",
      success: function(res) {
        console.log('转发成功')
        console.log(res)
      },
      fail: function(res) {
        // 转发失败 
        console.log('转发失败')
        console.log(res)
      }
    }
  },
  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var timestamp = Date.parse(new Date());  
    // date2 = timestamp / 1000;
     var n = timestamp;  
     var date2 = new Date(n);  
    console.log(date2)
    // var date2 = date.toLocaleDateString()
    var Y = date2.getFullYear() + '-';
    var M = (date2.getMonth()+1 < 10 ? '0'+(date2.getMonth()+1) : date2.getMonth()+1) + '-';
    var D = Y+M+date2.getDate() + ' ';
    console.log(D)
    this.setData({date:D})
    wx.setStorageSync('frfr', 'data')
    // wx.getStorageInfoSync('openid')
    var open = wx.getStorageSync('openid')
    console.log('open:')
    console.log(open)
    this.setData({acid:options.acid,site:options.site})
    // this.setData({acid:145,site:1})
    // this.setData({acid:'210'})
    // site为2，是楼下
    //  var url3 = 'https://open.weixin.qq.com/sns/getexpappinfo?appid=wxe329ad2878856a4c&path=pages%2Faacplace%2Faacplace.html%3Fid%3D'+ this.data.acid+'%26site%3D'+ this.data.site+'%26state%3D1#wechat-redirect';
    //  var url3 = 'https://open.weixin.qq.com/sns/getexpappinfo?appid=wxe329ad2878856a4c&path=pages%2Faacplace%2Faacplace.html%3Fid%3D264%26site%3D3&26state%3D1#wechat-redirect';
     
     var url3 = 'https://www.juquduo.com/juquduo/wechat/getUnlimited?page=pages/aacplace/aacplace&scene='+ this.data.acid+'.'+ this.data.site+'.1';
     console.log(url3)
    
  this.setData({UnlimitedCode2:url3})
  console.log(url3)
  },
  //2个时间
  bindTimeChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      time: e.detail.value
    })
  },
  bindTimeChange2: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      time2: e.detail.value
    })
  },
  zhuye(){
    wx.redirectTo({
      url: '../ayeshou/yeshou',
    })
  },
  //弹窗  
  buttonTap: function() {
    var times = this.data.date +' '+this.data.time;
    var stamp1 = new Date(times.replace(/-/g,"/")).getTime()/1000
    console.log(stamp1)
    var timee = this.data.date+' ' + this.data.time2;
    var stamp2 = new Date(timee.replace(/-/g,"/")).getTime()/1000
    wx.request({
      url: 'https://www.juquduo.com/juquduo/activity/share_activity',
      data:{
        activityBeginTime:stamp1,
        activityEndTime:stamp2,
        activityCover:this.data.img1,
        activityId:this.data.acid
      },
      success(res){
        console.log(res)
      }})
    this.setData({
      modalHidden: false
    })
    // this.ewmChange()
  },
  modalConfirm: function() {
    // this.setData({
    //   modalHidden: true
    // })
    wx.request({
      url: 'https://www.juquduo.com/juquduo/wechat/getUnlimited?page=pages/aacplace/aacplace&id=271&site=4&state=1',
      data:{},
      success(res){
        console.log(res)
      }
    })
  },
  modalCandel: function() {
    this.setData({
      modalHidden: true
    })
  },
  // ewmChange(){
  //   let size = {}
  //   size.w = wx.getSystemInfoSync().windowWidth / 750 * 500
  //   size.h = size.w
  //   var that = this

  //   drawQrcode({
  //     width: size.w,
  //     height: size.h,
  //     canvasId: 'myQrcode',
  //     // ctx: wx.createCanvasContext('myQrcode'),
  //     text: that.data.text,
  //     // v1.0.0+版本支持在二维码上绘制图片
  //   })
  // },
  tupian(){
    //添加Banner  
    var that = this;
    wx.chooseImage({
      count: 1,  //最多可以选择的图片总数  
      sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有  
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有  
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片  
        var tempFilePaths = res.tempFilePaths;
        // 替换显示的图片，用于页面显示
        that.setData({chuantu:tempFilePaths})
        console.log(res)
          wx.uploadFile({
            url: 'https://www.juquduo.com/uploadsFile',
            filePath: tempFilePaths[0],
            name: 'uploadsFile',
            formData: {
              // 'imgIndex': i,
            },
            header: {
              "Content-Type": "multipart / form-data"
            },
            success: function (res) {
              // console.log(JSON.stringify(res.data))
              console.log(res.data)
              // that.setData({D:res.data,text4:'已上传'})
              that.setData({img1:res.data})
            },
            fail:function(res){
              console.log(res)
            }});}});},
})